import { DatePipe } from '@angular/common';
import { BusiProvider } from './../../providers/busi/busi';
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { NativeProvider } from '../../providers/native/native';
import * as moment from "moment"
/**
 * Generated class for the UsereditPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-useredit',
  templateUrl: 'useredit.html',
})
export class UsereditPage {
  xb:any;
  csrq:any;
  xm:any;
  sjh:any;
  sfzhm:any;
  jtzz:any;
  datePipe: DatePipe = new DatePipe("en");
  constructor(public navCtrl: NavController, public navParams: NavParams,private busi: BusiProvider,private native: NativeProvider) {
    this.busi.getCurrentUserDetail().subscribe(
      data=>{
        this.xb = data.userdetail.xb;
        this.xm = data.userdetail.xm;
        this.sjh = data.userdetail.sjh;
        if(data.userdetail.csrq){
          var men = moment(data.userdetail.csrq, "YYYY-MM-DD");
          this.csrq =  this.datePipe.transform(men.toDate(),"yyyy-MM-dd");
        }
        this.sfzhm = data.userdetail.sfzhm;
        this.jtzz = data.userdetail.jtzz;
      },error=>{

      }
    );
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad UsereditPage');
  }

  save(){
    let body={
      xm:this.xm,
      xb:this.xb,
      sjh:this.sjh,
      csrq:this.csrq,
      sfzhm:this.sfzhm,
      jtzz:this.jtzz
    }
    this.busi.appUserModify(body).subscribe(
      ()=>{
        this.native.showToast("保存成功!");
        this.navCtrl.pop();
      },
      error=>{

      }
    );
  }

}
